import 'dart:convert';

class CardEntity {
  String picUrl;
  String text;

  CardEntity(
    this.picUrl,
    this.text,
  );

  CardEntity copyWith({
    String? picUrl,
    String? text,
  }) {
    return CardEntity(
      picUrl ?? this.picUrl,
      text ?? this.text,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'picUrl': picUrl,
      'text': text,
    };
  }

  factory CardEntity.fromMap(Map<String, dynamic> map) {
    return CardEntity(
      map['picUrl'] ?? '',
      map['text'] ?? '',
    );
  }

  String toJson() => json.encode(toMap());

  factory CardEntity.fromJson(String source) =>
      CardEntity.fromMap(json.decode(source));

  @override
  String toString() => 'CardEntity(picUrl: $picUrl, text: $text)';

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is CardEntity && other.picUrl == picUrl && other.text == text;
  }

  @override
  int get hashCode => picUrl.hashCode ^ text.hashCode;
}

class ToolBarEntity {
  String picUrl;
  String title;
  String url;

  ToolBarEntity(
    this.picUrl,
    this.title,
    this.url,
  );

  ToolBarEntity copyWith({
    String? picUrl,
    String? title,
    String? url,
  }) {
    return ToolBarEntity(
      picUrl ?? this.picUrl,
      title ?? this.title,
      url ?? this.url,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'picUrl': picUrl,
      'title': title,
      'url': url,
    };
  }

  factory ToolBarEntity.fromMap(Map<String, dynamic> map) {
    return ToolBarEntity(
      map['picUrl'] ?? '',
      map['title'] ?? '',
      map['url'] ?? '',
    );
  }

  String toJson() => json.encode(toMap());

  factory ToolBarEntity.fromJson(String source) =>
      ToolBarEntity.fromMap(json.decode(source));

  @override
  String toString() =>
      'ToolBarEntity(picUrl: $picUrl, title: $title, url: $url)';

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is ToolBarEntity &&
        other.picUrl == picUrl &&
        other.title == title &&
        other.url == url;
  }

  @override
  int get hashCode => picUrl.hashCode ^ title.hashCode ^ url.hashCode;
}
